<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class HomeworkSubmit extends BaseController {
    public function __construct() {
        parent::__construct();

        // 移动端初始化方法
        $this->wx_init();
        
        // 加载库
        $this->load->model('schoolModel');
        // $this->load->model('configModel');
        $this->load->model('contentModel');
        $this->load->model('classesModel');
        // $this->load->model('dataModel');
        // $this->load->model('wxUserModel');
    }

    // 教师角色
    /*
     * 作业提交列表页面
    */
    public function homework_submit($homeworkId) {
        $this->htmlTitle = '作业提交列表';
        // 获取作业详情
        $homeworkInfo = $this->contentModel->get_homework_info($homeworkId);
        // 获取作业发布班级的学生列表
        $stuParams['schoolId'] = $this->user['school_id'];
        $stuParams['homeworkId'] = $homeworkId;
        $stuParams['classORteach'] = $homeworkInfo['class_id'];
        $stuParams['isDelete'] = 0;
        $studentList = $this->schoolModel->get_student_list($stuParams);

        // 获取该学生的作业提交
        $submitParams['schoolId'] = $this->user['school_id'];
        $submitParams['homeworkId'] = $homeworkId;
        $submitParams['isCurrent'] = 1;
        $submitParams['isDelete'] = 0;
        $submitList = $this->contentModel->get_homework_submit_list($submitParams);
        // 使用学生id作为键值
        $submitList = array_value_to_key($submitList, 'student_id');
        $submitStudentList = array();       // 已提交
        $notSubmitStudentList = array();    // 未提交
        $reviewStudentList = array();       // 已批阅
        $notReviewStudentList = array();    // 待批阅
        $excellentStudentList = array();    // 优秀
        $reviseStudentList = array();       // 已订正
        $notReviseStudentList = array();    // 待订正
        foreach($studentList as $student) {
            if(isset($submitList[$student['id']])) {
                $submitStudentList[] = $student;
                if($submitList[$student['id']]['state'] == HOMEWORK_SUBMIT_STATE_NOT_REVIEW) {
                    // 待批阅
                    $notReviewStudentList[] = $student;
                } elseif($submitList[$student['id']]['state'] == HOMEWORK_SUBMIT_STATE_REVIEW) {
                    // 已批阅
                    $reviewStudentList[] = $student;
                    if($submitList[$student['id']]['is_excellent'] == 1) {
                        // 优秀
                        $excellentStudentList[] = $student;
                    }
                } elseif($submitList[$student['id']]['state'] == HOMEWORK_SUBMIT_STATE_NOT_REVISE) {
                    // 待订正
                    $notReviseStudentList[] = $student;
                } elseif($submitList[$student['id']]['state'] == HOMEWORK_SUBMIT_STATE_REVISE) {
                    // 已订正
                    $reviseStudentList[] = $student;
                }
            } else {
                // 未提交
                $notSubmitStudentList[] = $student;
            }
        }
        // echo '<pre>';var_export($submitList);exit;
        $this->dataArr = array(
            'submit' => $submitStudentList,
            'not_submit' => $notSubmitStudentList,
            'review' => $reviewStudentList,
            'not_review' => $notReviewStudentList,
            'excellent' => $excellentStudentList,
            'revise' => $reviseStudentList,
            'not_revise' => $notReviseStudentList
        );
        $this->homeworkId = $homeworkId;
        $this->display(WX_DIR . DIRECTORY_SEPARATOR . 'homework_submit' . DIRECTORY_SEPARATOR . 'homework_submit');
    }
    /*
     * 学生作业提交详情页面
    */
    public function homework_submit_detail($homeworkId) {
       
        $this->htmlTitle = '作业详情';
        if(empty($this->get('student_id'))) {
            throw new Exception('服务异常，请联系管理员');
        }
        // 获取学生信息
        $studentInfo = $this->schoolModel->get_student_info($this->get('student_id'));
        if(empty($studentInfo)) {
            throw new Exception('服务异常，请联系管理员');
        }
        // 获取班级名称
        $classInfo = $this->classesModel->get_class_info($studentInfo['class_id']);
        $studentInfo['class_name'] = $classInfo['class_name'];

        // 获取作业提交列表
        $submitParams['schoolId'] = $this->user['school_id'];
        $submitParams['homeworkId'] = $homeworkId;
        $submitParams['studentId'] = $studentInfo['id'];
        $submitParams['isDelete'] = 0;
        $submitList = $this->contentModel->get_homework_submit_list($submitParams);
        // 第一条为最新提交，后面的为订正历史
        if(empty($submitList)) {
            throw new Exception('无提交记录');
        }
        require_once('vendor/autoload.php');
        // 初始化又拍云接口
        $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
        $upyun = new Upyun\Upyun($config);
        foreach($submitList as $key => $item) {
            // 获取动态图片
            $submitList[$key]['imgArr'] = $this->_get_img_arr($item['imgs']);
            if(trim($item['audios'])) {
                // 获取音频时长
                $audioArr = json_decode($item['audios'], true);
                foreach($audioArr as $audioKey => $audio) {
                    $upyunLink = str_replace(UP_URL, '', $audio['link']);
                    $upyunInfo = $upyun->avMeta($upyunLink);
                    if(isset($upyunInfo['format']) && isset($upyunInfo['format']['duration'])) {
                        $duration = $upyunInfo['format']['duration'];
                        // 向下取整
                        $duration = floor($duration);
                        // 秒数转换为分秒格式02:01
                        $audioArr[$audioKey]['duration'] = handle_audio_duration($duration);
                    } else {
                        // 去掉该音频
                        unset($audioArr[$audioKey]);
                    }
                }
                $submitList[$key]['audioArr'] = $audioArr;
            }
            if(trim($item['videos'])) {
                $videoArr = json_decode($item['videos'], true);
                foreach($videoArr  as $videoKey => $video) {
                    // 判断视频压缩是否完成
                    // 返回false即视频不存在
                    $linkUpyun = str_replace(UP_URL, '', $video['link']);
                    if($upyun->has($linkUpyun)) {
                        // 转码完成
                        $videoArr[$videoKey]['href'] = $video['link'];
                    } else {
                        $videoArr[$videoKey]['href'] = $video['old_link'];
                    }
                }
                $submitList[$key]['videoArr'] = $videoArr;
            }
            // 转换updatetime为格式：时间去掉秒
            $submitList[$key]['updatetimeFormat'] = time_remove_second($item['updatetime']);
            // 获取审核老师信息
            if($item['revise_teacher_id']) {
                $userInfo = $this->schoolModel->get_school_user_info_realname($item['revise_teacher_id']);
                $submitList[$key]['reviseTeacherInfo'] = $userInfo;
                // 获取审核图片
                $reviseImgArr = array();
                if($item['revise_imgs']) {
                    $reviseImgArr = explode(',', $item['revise_imgs']);
                }
                $submitList[$key]['reviseImgArr'] = $reviseImgArr; 
            }
        }
        // 最新作业提交
        $this->currentSubmit = $submitList[0];
        // 去掉第一条，后面的就是订正历史
        array_shift($submitList);
        // 订正历史
        $this->submitHistoryList = $submitList;
        $this->studentInfo = $studentInfo;
        // echo '<pre>';var_export($this->currentSubmit);exit;
        // 获取jssdk参数
        $this->load->library('wechat');
        $url = substr(BASE_URL, 0 , -1) . $_SERVER['REQUEST_URI'];
        $this->dataJssdk = $this->wechat->jssdk_data($url);

        $this->display(WX_DIR . DIRECTORY_SEPARATOR . 'homework_submit' . DIRECTORY_SEPARATOR . 'homework_submit_detail');
    }
    /*
     * 批阅作业页面
    */
    public function homework_submit_review($homeworkSubmitId) {
        $homeworkSubmitInfo = $this->contentModel->get_homework_submit_info($homeworkSubmitId);
        if(empty($homeworkSubmitInfo)) {
            throw new Exception('服务异常，请联系管理员');
        }
        $homeworkInfo = $this->contentModel->get_homework_info($homeworkSubmitInfo['homework_id']);
        // 转换updatetime为格式：2019.10.10
        $homeworkInfo['updatetimeFormat'] = format_time_to_date($homeworkInfo['updatetime']);
        // 获取发布人姓名
        $userInfo = $this->schoolModel->get_school_user_info_realname($homeworkInfo['user_id']);
        $homeworkInfo['realname'] = $userInfo['realname'];
        // 获取动态图片
        require_once('vendor/autoload.php');
        // 初始化又拍云接口
        $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
        $upyun = new Upyun\Upyun($config);
        $homeworkSubmitInfo['imgArr'] = $this->_get_img_arr($homeworkSubmitInfo['imgs']);
        if(trim($homeworkSubmitInfo['audios'])) {
            // 获取音频时长
            $homeworkSubmitInfo['audioArr'] = json_decode($homeworkSubmitInfo['audios'], true);
            foreach($homeworkSubmitInfo['audioArr'] as $key => $audio) {
                $upyunLink = str_replace(UP_URL, '', $audio['link']);
                $upyunInfo = $upyun->avMeta($upyunLink);
                if(isset($upyunInfo['format']) && isset($upyunInfo['format']['duration'])) {
                    $duration = $upyunInfo['format']['duration'];
                    // 向下取整
                    $duration = floor($duration);
                    // 秒数转换为分秒格式02:01
                    $homeworkSubmitInfo['audioArr'][$key]['duration'] = handle_audio_duration($duration);
                } else {
                    // 去掉该音频
                    unset($homeworkSubmitInfo['audioArr'][$key]);
                }
            }
        }
        if(trim($homeworkSubmitInfo['videos'])) {
            $homeworkSubmitInfo['videoArr'] = json_decode($homeworkSubmitInfo['videos'], true);
            foreach($homeworkSubmitInfo['videoArr']  as &$video) {
                // 判断视频压缩是否完成
                // 返回false即视频不存在
                $linkUpyun = str_replace(UP_URL, '', $video['link']);
                if($upyun->has($linkUpyun)) {
                    // 转码完成
                    $video['href'] = $video['link'];
                } else {
                    $video['href'] = $video['old_link'];
                }
            }
        }
        // 转换updatetime为格式：时间去掉秒
        $homeworkSubmitInfo['updatetimeFormat'] = time_remove_second($homeworkSubmitInfo['updatetime']);
        // 获取学生信息
        $studentInfo = $this->schoolModel->get_student_info($homeworkSubmitInfo['student_id']);
        // 获取班级信息
        $classInfo = $this->classesModel->get_class_info($studentInfo['class_id']);
        $studentInfo['class_name'] = $classInfo['class_name'];
        $homeworkSubmitInfo['studentInfo'] = $studentInfo;
        // 审核图片
        if($homeworkSubmitInfo['revise_imgs']) {
            $homeworkSubmitInfo['reviseImgArr'] = $this->_get_img_arr($homeworkSubmitInfo['revise_imgs']);
        }

        // echo '<pre>';var_export($homeworkSubmitInfo);exit;
        // 获取jssdk参数
        $this->load->library('wechat');
        $url = substr(BASE_URL, 0 , -1) . $_SERVER['REQUEST_URI'];
        $this->dataJssdk = $this->wechat->jssdk_data($url);
        
        $this->homework = $homeworkInfo;
        $this->homeworkSubmit = $homeworkSubmitInfo;
        $this->htmlTitle = $studentInfo['realname'] . '作业';

        $this->display(WX_DIR . DIRECTORY_SEPARATOR . 'homework_submit' . DIRECTORY_SEPARATOR . 'homework_submit_review');
    }
    // 审核操作
    public function save_homework_submit_state_action() {
        $id = $this->post('id');
        $state = $this->post('state');
        $content = trim($this->post('revise_content'));
        $imgArr = $this->post('imgArr');
        $isExcellent = $this->post('is_excellent');
        if($state == HOMEWORK_SUBMIT_STATE_NOT_REVISE) {
            // 需订正
            $isExcellent = 0;
        }
        if($imgArr) {
            $imgs = implode(',', $imgArr);
        } else {
            $imgs = '';
        }

        $data = array(
            'id' => $id,
            'state' => $state,
            'revise_content' => $content,
            'revise_imgs' => $imgs,
            'revise_teacher_id' => $this->user['id'],
            'is_excellent' => $isExcellent,
            'revisetime' => date('Y-m-d H:i:s')
        );
        // var_export($isExcellent);exit;
        // 更新
        $this->db->update(ContentModel::$homeworkSubmitTable, $data, array('id' => $id));

        exit(json('提交成功', true));
    }

    // 学生角色
    /*
     * 编辑作业提交页面
    */
    public function homework_submit_edit($homeworkId) {
        if($this->get("is_revise") == 1) {
            $this->htmlTitle = '订正作业';
        } else {
            if($this->get('homework_submit_id')) {
                $this->htmlTitle = '修改作业';
            } else {
                $this->htmlTitle = '提交作业';
            }
        }
        $homeworkInfo = $this->contentModel->get_homework_info($homeworkId);
        // 转换updatetime为格式：2019.10.10
        $homeworkInfo['updatetimeFormat'] = format_time_to_date($homeworkInfo['updatetime']);
        // 获取发布人姓名
        $userInfo = $this->schoolModel->get_school_user_info_realname($homeworkInfo['user_id']);
        $homeworkInfo['realname'] = $userInfo['realname'];
        // 是否订正操作
        // 订正操作显示审核内容
        if($this->get('is_revise') == 1) {
            if($this->get('revise_homework_submit_id')) {
                // 获取需要订正的作业提交id
                $reviseHomeworkSubmitInfo = $this->contentModel->get_homework_submit_info($this->get('revise_homework_submit_id'));
                // 获取审核教师信息
                if($reviseHomeworkSubmitInfo['revise_teacher_id']) {
                    $userInfo = $this->schoolModel->get_school_user_info_realname($reviseHomeworkSubmitInfo['revise_teacher_id']);
                }
                $reviseHomeworkSubmitInfo['teacherInfo'] = $userInfo;
                // 获取审核图片
                $imgArr = array();
                if($reviseHomeworkSubmitInfo['revise_imgs']) {
                    $imgArr = explode(',', $reviseHomeworkSubmitInfo['revise_imgs']);
                }
                $reviseHomeworkSubmitInfo['imgArr'] = $imgArr; 
                $this->reviseHomeworkSubmitInfo = $reviseHomeworkSubmitInfo;
            }
        }
        // 修改操作
        if($this->get('homework_submit_id')) {
            $homeworkSubmitInfo = $this->contentModel->get_homework_submit_info($this->get('homework_submit_id'));
            if(empty($homeworkSubmitInfo)) {
                throw new Exception('服务异常，请联系管理员');
            }
            // 获取动态图片
            $homeworkSubmitInfo['imgArr'] = $this->_get_img_arr($homeworkSubmitInfo['imgs']);
            if(trim($homeworkSubmitInfo['audios'])) {
                // 获取音频时长
                $homeworkSubmitInfo['audioArr'] = json_decode($homeworkSubmitInfo['audios'], true);
                require_once('vendor/autoload.php');
                // 初始化又拍云接口
                $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
                $upyun = new Upyun\Upyun($config);
                foreach($homeworkSubmitInfo['audioArr'] as $key => $audio) {
                    $upyunLink = str_replace(UP_URL, '', $audio['link']);
                    $upyunInfo = $upyun->avMeta($upyunLink);
                    if(isset($upyunInfo['format']) && isset($upyunInfo['format']['duration'])) {
                        $duration = $upyunInfo['format']['duration'];
                        // 向下取整
                        $duration = floor($duration);
                        // 秒数转换为分秒格式02:01
                        $homeworkSubmitInfo['audioArr'][$key]['duration'] = handle_audio_duration($duration);
                    } else {
                        // 去掉该音频
                        unset($homeworkSubmitInfo['audioArr'][$key]);
                    }
                    // var_export(handle_audio_duration($duration));exit;
                }
                
            }
            if(trim($homeworkSubmitInfo['videos'])) {
                $homeworkSubmitInfo['videoArr'] = json_decode($homeworkSubmitInfo['videos'], true);
                require_once('vendor/autoload.php');
                // 初始化又拍云接口
                $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
                $upyun = new Upyun\Upyun($config);
                foreach($homeworkSubmitInfo['videoArr']  as &$video) {
                    // 判断视频压缩是否完成
                    // 返回false即视频不存在
                    $linkUpyun = str_replace(UP_URL, '', $video['link']);
                    if($upyun->has($linkUpyun)) {
                        // 转码完成
                        $video['href'] = $video['link'];
                    } else {
                        $video['href'] = $video['old_link'];
                    }
                }
            }
            $this->homeworkSubmit = $homeworkSubmitInfo;
            // 修改订正操作显示审核内容
            if($homeworkSubmitInfo['state'] == HOMEWORK_SUBMIT_STATE_REVISE) {
                // 获取最新的一条状态为‘待订正’的作业提交
                $reviseHomeworkSubmitParams['schoolId'] = $this->user['school_id'];
                $reviseHomeworkSubmitParams['studentId'] = $this->user['id'];
                $reviseHomeworkSubmitParams['homeworkId'] = $homeworkId;
                $reviseHomeworkSubmitParams['state'] = HOMEWORK_SUBMIT_STATE_NOT_REVISE;
                $reviseHomeworkSubmitParams['isDelete'] = 0;
                $reviseHomeworkSubmitList = $this->contentModel->get_homework_submit_list($reviseHomeworkSubmitParams);
                if($reviseHomeworkSubmitList) {
                    $reviseHomeworkSubmitInfo = $reviseHomeworkSubmitList[0];
                    // 获取审核教师信息
                    if($reviseHomeworkSubmitInfo['revise_teacher_id']) {
                        $userInfo = $this->schoolModel->get_school_user_info_realname($reviseHomeworkSubmitInfo['revise_teacher_id']);
                    }
                    $reviseHomeworkSubmitInfo['teacherInfo'] = $userInfo;
                    // 获取审核图片
                    $imgArr = array();
                    if($reviseHomeworkSubmitInfo['revise_imgs']) {
                        $imgArr = explode(',', $reviseHomeworkSubmitInfo['revise_imgs']);
                    }
                    $reviseHomeworkSubmitInfo['imgArr'] = $imgArr; 
                    $this->reviseHomeworkSubmitInfo = $reviseHomeworkSubmitInfo;
                }               
            }
        }
        $this->homework = $homeworkInfo;
        $this->isRevise = $this->get("is_revise") == 1 ? 1 : 0;
        // echo '<pre>';var_export($reviseHomeworkSubmitInfo);exit;
        // 获取jssdk参数
        $this->load->library('wechat');
        $url = substr(BASE_URL, 0 , -1) . $_SERVER['REQUEST_URI'];
        $this->dataJssdk = $this->wechat->jssdk_data($url);
        // 生成又拍云签名
        require_once('vendor/autoload.php');
        $serviceConfig = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
        $serviceConfig->setFormApiKey(UP_FORM_API);
        $serviceConfig->getImageUploadParams(UP_FILEPATH, $this->policy, $this->signature);
        $this->display(WX_DIR . DIRECTORY_SEPARATOR . 'homework_submit' . DIRECTORY_SEPARATOR . 'homework_submit_edit');
    }
    // 保存动态操作
    public function save_homework_submit_action() {
        // 是否订正操作
        $isRevise = $this->post('is_revise') == 1 ? 1 : 0;
        $id = $this->post('id');
        $homeworkId = $this->post('homework_id');
        $content = trim($this->post('content'));
        $imgArr = $this->post('imgArr');
        $audios = $this->post('audios') ? json_encode($this->post('audios'), JSON_UNESCAPED_UNICODE) : '';
        $videos = $this->post('video_arr') ? json_encode($this->post('video_arr'), JSON_UNESCAPED_UNICODE) : '';
        if(empty($homeworkId)) {
            throw new Exception('服务异常，请联系管理员');
        }
        if($imgArr) {
            $imgs = implode(',', $imgArr);
        } else {
            $imgs = '';
        }
        if($this->post('video_arr') && 9 < count($this->post('video_arr'))) {
            throw new Exception("最多只能上传9个视频");
        }

        $data = array(
            'school_id' => $this->user['school_id'],
            'campus_id' => $this->user['campus_id'],
            'student_id' => $this->user['id'],
            'homework_id' => $homeworkId,
            'content' => $content,
            'imgs' => $imgs,
            'videos' => $videos,
            'audios' => $audios,
            'is_current' => 1,
            'is_delete' => 0,
            'updatetime' => date('Y-m-d H:i:s')
        );
        // 设置其他作业提交is_current=0
        $this->db->update(ContentModel::$homeworkSubmitTable, array(
            'is_current' =>  0
        ), array(
            'homework_id' => $homeworkId,
            'student_id' => $this->user['id'],
            'is_current' => 1
        ));

        // 操作
        $action = '';
        if(empty($id)) {
            // 插入
            $data['createtime'] = date('Y-m-d H:i:s');
            // 状态
            $state = $isRevise ? HOMEWORK_SUBMIT_STATE_REVISE : HOMEWORK_SUBMIT_STATE_NOT_REVIEW;
            $data['state'] = $state;
            $this->db->insert(ContentModel::$homeworkSubmitTable, $data);
        } else {
            // 更新
            $this->db->update(ContentModel::$homeworkSubmitTable, $data, array('id' => $id));
        }
     
        exit(json('提交成功', true));
    }

    // 获取图片
    private function _get_img_arr($imgs) {
        if(empty($imgs)) {
            return array(
                'imgAll' => array(),
                'imgBeforeEight' => array()
            );
        }
        $imgArr = explode(',', $imgs);   
        $arr['imgAll'] = $imgArr;
        // 如大于8张，取前8张
        $imgBeforeEight = $imgArr;
        $imgAfterEight = array();
        if(count($imgArr) > 8) {
            $imgBeforeEight = array_slice($imgArr, 0, 8);
            $imgAfterEight = array_slice($imgArr, 8);
        }
        $arr['imgBeforeEight'] = $imgBeforeEight;
        $arr['imgAfterEight'] = $imgAfterEight;
        return $arr;
    }
    /*
     * 查看作业提交页面
    */
    public function homework_submit_check($homeworkId) {
        // 是否订正操作
        $isRevise = $this->get("is_revise") == 1 ? 1 : 0;
        if($isRevise) {
            $this->htmlTitle = '订正作业';
        } else {
            $this->htmlTitle = '查看作业';
        }
        if(empty($this->get('homework_submit_id'))) {
            throw new Exception('服务异常，请联系管理员');
        }
        $homeworkSubmitInfo = $this->contentModel->get_homework_submit_info($this->get('homework_submit_id'));
        if(empty($homeworkSubmitInfo)) {
            throw new Exception('服务异常，请联系管理员');
        }
        // 获取动态图片
        require_once('vendor/autoload.php');
        // 初始化又拍云接口
        $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
        $upyun = new Upyun\Upyun($config);
        $homeworkSubmitInfo['imgArr'] = $this->_get_img_arr($homeworkSubmitInfo['imgs']);
        if(trim($homeworkSubmitInfo['audios'])) {
            // 获取音频时长
            $homeworkSubmitInfo['audioArr'] = json_decode($homeworkSubmitInfo['audios'], true);
            foreach($homeworkSubmitInfo['audioArr'] as $key => $audio) {
                $upyunLink = str_replace(UP_URL, '', $audio['link']);
                $upyunInfo = $upyun->avMeta($upyunLink);
                if(isset($upyunInfo['format']) && isset($upyunInfo['format']['duration'])) {
                    $duration = $upyunInfo['format']['duration'];
                    // 向下取整
                    $duration = floor($duration);
                    // 秒数转换为分秒格式02:01
                    $homeworkSubmitInfo['audioArr'][$key]['duration'] = handle_audio_duration($duration);
                } else {
                    // 去掉该音频
                    unset($homeworkSubmitInfo['audioArr'][$key]);
                }
            }
        }
        if(trim($homeworkSubmitInfo['videos'])) {
            $homeworkSubmitInfo['videoArr'] = json_decode($homeworkSubmitInfo['videos'], true);
            foreach($homeworkSubmitInfo['videoArr']  as &$video) {
                // 判断视频压缩是否完成
                // 返回false即视频不存在
                $linkUpyun = str_replace(UP_URL, '', $video['link']);
                if($upyun->has($linkUpyun)) {
                    // 转码完成
                    $video['href'] = $video['link'];
                } else {
                    $video['href'] = $video['old_link'];
                }
            }
        }
        // 转换updatetime为格式：时间去掉秒
        $homeworkSubmitInfo['updatetimeFormat'] = time_remove_second($homeworkSubmitInfo['updatetime']);
        // 获取学生信息
        $studentInfo = $this->schoolModel->get_student_info($homeworkSubmitInfo['student_id']);
        // 获取班级名称
        $classInfo = $this->classesModel->get_class_info($studentInfo['class_id']);
        $studentInfo['class_name'] = $classInfo['class_name'];
        $homeworkSubmitInfo['studentInfo'] = $studentInfo;
        // 获取审核老师信息
        // if($isRevise) {
        //     $userInfo = array();
        //     if($homeworkSubmitInfo['revise_teacher_id']) {
        //         $userInfo = $this->schoolModel->get_school_user_info_realname($homeworkSubmitInfo['revise_teacher_id']);
        //     }
        //     $homeworkSubmitInfo['teacherInfo'] = $userInfo;
        //     // 获取审核图片
        //     $imgArr = array();
        //     if($homeworkSubmitInfo['revise_imgs']) {
        //         $imgArr = explode(',', $homeworkSubmitInfo['revise_imgs']);
        //     }
        //     $homeworkSubmitInfo['reviseImgArr'] = $imgArr; 
        // }
        // 获取最新的一条状态为‘待订正’的作业提交
        $historyList = array();
        $reviseHomeworkSubmitParams['schoolId'] = $this->user['school_id'];
        $reviseHomeworkSubmitParams['studentId'] = $this->user['id'];
        $reviseHomeworkSubmitParams['homeworkId'] = $homeworkId;
        $reviseHomeworkSubmitParams['state'] = HOMEWORK_SUBMIT_STATE_NOT_REVISE;
        $reviseHomeworkSubmitParams['isDelete'] = 0;
        $reviseHomeworkSubmitList = $this->contentModel->get_homework_submit_list($reviseHomeworkSubmitParams);
        if($reviseHomeworkSubmitList) {
            foreach($reviseHomeworkSubmitList as $reviseHomeworkSubmitInfo) {
                $history = array();
                $history['revise_content'] = $reviseHomeworkSubmitInfo['revise_content'];
                // 获取审核教师信息
                $userInfo = array();
                if($reviseHomeworkSubmitInfo['revise_teacher_id']) {
                    $userInfo = $this->schoolModel->get_school_user_info_realname($reviseHomeworkSubmitInfo['revise_teacher_id']);
                }
                $history['teacherInfo'] = $userInfo;
                // 获取审核图片
                $imgArr = array();
                if($reviseHomeworkSubmitInfo['revise_imgs']) {
                    $imgArr = explode(',', $reviseHomeworkSubmitInfo['revise_imgs']);
                }
                $history['imgArr'] = $imgArr; 
                $historyList[] = $history;
            }
        }
        $this->historyList = $historyList;
        $this->homeworkSubmit = $homeworkSubmitInfo;
        $this->homeworkId = $homeworkId;
        $this->isRevise = $isRevise;
        // echo '<pre>';var_export($userInfo);exit;
        // 获取jssdk参数
        $this->load->library('wechat');
        $url = substr(BASE_URL, 0 , -1) . $_SERVER['REQUEST_URI'];
        $this->dataJssdk = $this->wechat->jssdk_data($url);

        $this->display(WX_DIR . DIRECTORY_SEPARATOR . 'homework_submit' . DIRECTORY_SEPARATOR . 'homework_submit_check');
    }
}